﻿

//在原有DAO 加入下面两个方法
	
	/**
	 * 查询结果集的行数
	 */
	public int getTotalDaoHuos(DaoHuo daoHuo) throws DaoException {
		//logger.debug("getQueryRows()  - run");

		StringBuffer sb = new StringBuffer();
		sb.append("SELECT COUNT(1) FROM SH_YL_DAO_HUO_T WHERE 1=1");
		
		if (daoHuo.getYgId() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.YG_ID =" + daoHuo.getYgId());
		}
		if (null != daoHuo.getYuanGong() && !daoHuo.getYuanGong().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_T.YUAN_GONG LIKE '%" + daoHuo.getYuanGong().trim() + "%'");
		}
		if (daoHuo.getDhDate() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.DH_DATE =" + daoHuo.getDhDate());
		}
		if (daoHuo.getStatus() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.STATUS =" + daoHuo.getStatus());
		}
		if (null != daoHuo.getBeiZhu() && !daoHuo.getBeiZhu().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_T.BEI_ZHU LIKE '%" + daoHuo.getBeiZhu().trim() + "%'");
		}
		if (daoHuo.getGysId() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.GYS_ID =" + daoHuo.getGysId());
		}
		if (null != daoHuo.getDhSet() && !daoHuo.getDhSet().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_T.DH_SET LIKE '%" + daoHuo.getDhSet().trim() + "%'");
		}
		if (daoHuo.getDhType() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.DH_TYPE =" + daoHuo.getDhType());
		}

		String sql = sb.toString();
		return queryInt(sql);		
	}
	
	/**
	 * 返回带查询条件的到货单结果集并排序
	 */
	public List getDaoHuos(String property, String sortOrder,int limit, int offset,DaoHuo daoHuo) throws DaoException {
		//logger.debug("List getDaoHuos(String property, String sortOrder,int limit, int offset,DaoHuo daoHuo) --run"); 
		
		
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT DH_ID,YG_ID,YUAN_GONG,DH_DATE,STATUS,BEI_ZHU,GYS_ID,DH_SET,DH_TYPE  FROM SH_YL_DAO_HUO_T WHERE 1=1");
		
		if (daoHuo.getYgId() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.YG_ID =" + daoHuo.getYgId());
		}
		if (null != daoHuo.getYuanGong() && !daoHuo.getYuanGong().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_T.YUAN_GONG LIKE '%" + daoHuo.getYuanGong().trim() + "%'");
		}
		if (daoHuo.getDhDate() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.DH_DATE =" + daoHuo.getDhDate());
		}
		if (daoHuo.getStatus() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.STATUS =" + daoHuo.getStatus());
		}
		if (null != daoHuo.getBeiZhu() && !daoHuo.getBeiZhu().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_T.BEI_ZHU LIKE '%" + daoHuo.getBeiZhu().trim() + "%'");
		}
		if (daoHuo.getGysId() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.GYS_ID =" + daoHuo.getGysId());
		}
		if (null != daoHuo.getDhSet() && !daoHuo.getDhSet().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_T.DH_SET LIKE '%" + daoHuo.getDhSet().trim() + "%'");
		}
		if (daoHuo.getDhType() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_T.DH_TYPE =" + daoHuo.getDhType());
		}
		
		if (property != null && sortOrder != null) {
			sb.append(" ORDER BY ");
			sb.append(" ");
			sb.append(property);
			sb.append(" ");
			sb.append(sortOrder);
		} else{
			sb.append(" ORDER BY DH_ID DESC ");
		}
		
		//logger.debug("List getDaoHuos(String property, String sortOrder,int limit, int offset)- end"); 
		return queryList(sb.toString(),limit,offset);
	}
	
